package com.service;

import com.bean.Department;
import com.bean.Employee;
import com.bean.Salary;
import com.dao.DepartmentDao;
import com.dao.EmployeeDao;
import com.dao.SalaryDao;

import java.util.List;

/**
 * TODO提供普通职工的业务操作
 *
 */
public class EmployeeService {
    /**
     * 该方法主要使用正则表达式来判断字符串是否是数字
     *
     */
    public boolean judgeContainsStr(String cardNum) {
        boolean isNum = cardNum.matches("[0-9]+");
        return isNum;
    }
    public Employee getEmployee(String id){
        EmployeeDao employeeDao=new EmployeeDao();
        return employeeDao.getEmployee(id);
    }
    public boolean checkLogin(String id,String password){
        Employee employee=getEmployee(id);
        if (employee==null)
            return false;
        if(password.equals(employee.getPassword()))
            return true;
        return false;
    }
    public boolean changePassword(String id,String oldpassword,String newpassword){
        Employee employee=getEmployee(id);
        if(oldpassword.equals(employee.getPassword())){
            employee.setPassword(newpassword);
            EmployeeDao employeeDao=new EmployeeDao();
            employeeDao.updateEmployee(employee);
            return true;
        }
        return false;
    }
    public Employee searchSelf(String id){
        EmployeeDao employeeDao=new EmployeeDao();
        return employeeDao.getEmployee(id);
    }

    public List<Department> getDept(){
        DepartmentDao departmentDao=new DepartmentDao();
        return departmentDao.getDepartmentList();
    }
    public List<Salary> getSalaryByuser(String id, String year){
        SalaryDao salaryDao=new SalaryDao();
        return salaryDao.getSalaryListByUserYear(id,year);
    }
}
